package com.qingke.hibernate.bean;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

import org.hibernate.CallbackException;
import org.hibernate.Session;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.classic.Lifecycle;


@Entity
@Table(name="student")
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class Student implements Lifecycle{
	@Id
	@Column(name="id")
	private int id;
	
	@Column(name="sid")
	private int sid;
	
	@Column(name="firstname")
	private String firstname;
	
	@Column(name="lastname")
	private String lastname;
	
	@Column(name="phone")
	private String phone;
	
	@Column(name="email")
	private String email;
	
	@Column(name="gender")
	private String gender;
	
	@Column(name="age")
	private int age;
	
//	@Column(name="student_status_id")
//	private int studentStatusId;
	
	@ManyToOne
	@JoinColumn(name="student_status_id")
//	@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
	private StudentStatus studentStatus;
	
	@OneToOne
	@JoinColumn(name="accommodation_id")
//	@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
	private Accommodation accommodation;
//	@Column(name="accommodation_id")
//	private int accommodationId;
	
	@OneToOne
//	@JoinColumn(name="id")
	@PrimaryKeyJoinColumn
	private StudentLogin studentLogin;
	
//	@ManyToMany(mappedBy="students")
//	private Set<Teacher> teachers;
	
	@OneToMany(mappedBy="student")
	private Set<SelectCourse> selectCourses;
	
	@OneToOne(mappedBy="student")
	private Register register;
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public int getSid() {
		return sid;
	}
	public void setSid(int sid) {
		this.sid = sid;
	}
	public String getFirstname() {
		return firstname;
	}
	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}
	public String getLastname() {
		return lastname;
	}
	public void setLastname(String lastname) {
		this.lastname = lastname;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getGender() {
		return gender;
	}
	public void setGender(String gender) {
		this.gender = gender;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
//	public int getStudentStatusId() {
//		return studentStatusId;
//	}
//	public void setStudentStatusId(int studentStatusId) {
//		this.studentStatusId = studentStatusId;
//	}
	
	public StudentStatus getStudentStatus() {
		return studentStatus;
	}
	public void setStudentStatus(StudentStatus studentStatus) {
		this.studentStatus = studentStatus;
	}
//	public int getAccommodationId() {
//		return accommodationId;
//	}
//	public void setAccommodationId(int accommodationId) {
//		this.accommodationId = accommodationId;
//	}
	
	public StudentLogin getStudentLogin() {
		return studentLogin;
	}
	public Accommodation getAccommodation() {
		return accommodation;
	}
	public void setAccommodation(Accommodation accommodation) {
		this.accommodation = accommodation;
	}
	public void setStudentLogin(StudentLogin studentLogin) {
		this.studentLogin = studentLogin;
	}
	
//	public Set<Teacher> getTeachers() {
//		return teachers;
//	}
//	public void setTeachers(Set<Teacher> teachers) {
//		this.teachers = teachers;
//	}
	
	
	public Set<SelectCourse> getSelectCourses() {
		return selectCourses;
	}
	public void setSelectCourses(Set<SelectCourse> selectCourses) {
		this.selectCourses = selectCourses;
	}
	public Register getRegister() {
		return register;
	}
	public void setRegister(Register register) {
		this.register = register;
	}
	@Override
	public String toString() {
		return "Student [id=" + id + ", sid=" + sid + ", name=" + lastname + firstname + ", phone="
				+ phone + ", email=" + email + ", gender=" + gender + ", age=" + age + ", studentStatus="
				+ studentStatus + ", accommodation=" + accommodation + "]";
	}
	@Override
	public boolean onSave(Session s) throws CallbackException {
		System.out.println("calling onSave..."+new Date(System.currentTimeMillis()));
		return false;
	}
	@Override
	public boolean onUpdate(Session s) throws CallbackException {
		System.out.println("calling onUpdate..."+new Date(System.currentTimeMillis()));
		return false;
	}
	@Override
	public boolean onDelete(Session s) throws CallbackException {
		System.out.println("calling onDelete..."+new Date(System.currentTimeMillis()));
		return false;
	}
	@Override
	public void onLoad(Session s, Serializable id) {
		System.out.println("calling onLoad..."+new Date(System.currentTimeMillis()));
	}

	
}
